package com.lc.dao;

import com.lc.config.annos.Autowired;
import com.lc.config.annos.Repository;
import com.lc.datasource.DataSourceContext;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @author liuc
 * @date 2021/4/18
 * @description
 **/
@Repository("accountMapper")
public class AccountMapperImpl implements AccountMapper{

    @Autowired
    private DataSourceContext dataSourceContext;

    @Override
    public void transfer(int accountNo, int num) throws SQLException {
        Connection con = dataSourceContext.getConnection();
        String sql = "update account set money = money - ? where id = ?";
        PreparedStatement preparedStatement = con.prepareStatement(sql);
        preparedStatement.setInt(1,num);
        preparedStatement.setInt(2,accountNo);
        preparedStatement.executeUpdate();
    }
}
